//
//  LBMediaPresentViewController.m
//  LangBa
//
//  Created by Mac on 2017/12/21.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "LGShareViewController.h"
@interface LGShareViewController ()
@property(nonatomic, strong) STButton                     *clearButton;
@property(nonatomic, strong) UIView                     *customView;
@end

@implementation LGShareViewController

- (instancetype)init
{
    if (self == [super init]) {
        self.modalPresentationStyle = UIModalPresentationOverFullScreen;
    }
    return self;
}
#pragma mark --vc 生命周期
- (void)viewDidLoad{
    [super viewDidLoad];
    [self configSubView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self show];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    self.clearButton = [[STButton alloc] initWithFrame:UIScreenFrame
                                                 title:nil
                                            titleColor:nil
                                             titleFont:0
                                          cornerRadius:0
                                       backgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.4]
                                       backgroundImage:nil
                                                 image:nil];
    [weakSelf.clearButton setClicAction:^(UIButton *sender) {
        [weakSelf dismiss];
    }];
    [self.view addSubview:_clearButton];
    
    self.customView = [[UIView alloc] initWithFrame:CGRectMake(0, UIScreenHeight, UIScreenWidth, 100)];
    self.customView.centerX = UIScreenWidth / 2;
    self.customView.top = UIScreenHeight;
    self.customView.backgroundColor = [UIColor whiteColor];
    self.customView.layer.cornerRadius = 10;
    self.customView.clipsToBounds = YES;
    self.customView.centerY = UIScreenHeight / 2;
    [self.view addSubview:self.customView];
    
    UIImageView * imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.customView.width, 100)];
    imageview.image = [UIImage imageNamed:@"分享bg"];
    imageview.userInteractionEnabled = YES;
    [self.customView addSubview:imageview];

    NSArray * array = @[@{@"title":@"QQ",@"imageName":@"分享qq"},
                        @{@"title":@"微信",@"imageName":@"分享微信"},
                        @{@"title":@"朋友圈",@"imageName":@"分享朋友圈"},
                        @{@"title":@"微博",@"imageName":@"分享微博"}
                        ];
    CGFloat buttonWith = UIScreenWidth / 4;
    for (NSInteger i =0 ;i < array.count;i ++) {
        NSDictionary * dic = array[i];
        NSString * imageName = dic[@"imageName"];
        NSString * title = dic[@"title"];
        __weak typeof(self) weakSelf =  self;
        STMenuControl * menuControl = [[STMenuControl alloc] initWithFrame:CGRectMake(0, 0, buttonWith, 100) imageName:imageName title:title titleColor:FirstTextColor];
        [menuControl setOnSelctedControl:^(STMenuControl *control) {
            [weakSelf dismissWithHandle:^{
                if (weakSelf.onSelctedShareHandle) {
                    weakSelf.onSelctedShareHandle(title);
                }
            }];
        }];
        menuControl.tag = 10000 + i;
        [imageview addSubview:menuControl];
        menuControl.left = (i%4) * buttonWith;

    }
    self.customView.top = UIScreenHeight ;
}

#pragma mark --Private Method
- (void)show{
    [UIView animateWithDuration:0.6
                          delay:0
         usingSpringWithDamping:0.6
          initialSpringVelocity:0.7
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
                         self.customView.bottom = UIScreenHeight;
                     } completion:^(BOOL finished) {
                         
                     }];
}
- (void)dismiss{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.customView.top = UIScreenHeight;
        self.clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}
- (void)dismissWithHandle:(void(^)())handle{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.customView.top = UIScreenHeight;
        self.clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:^{
            if (handle) {
                handle();
            }
        }];
    }];
}
#pragma mark --Action Method

- (void)onSelectedCancleButton{
    
    [self dismiss];
    
}
- (void)onSelectedWhiteView{
    [self.view endEditing:YES];
}

@end






